using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SIGCBI.Entities;

namespace SIGCBI.Repository.Mapping
{
    public class BIENMap : EntityTypeConfiguration<BIEN>
    {
        public BIENMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.ID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(t => t.Codigo)
                .HasMaxLength(50);

            this.Property(t => t.Nombre)
                .HasMaxLength(350);

            this.Property(t => t.Caracteristicas)
                .HasColumnType("text")
                .IsRequired();

            // Table & Column Mappings
            this.ToTable("BIEN");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Codigo).HasColumnName("Codigo");
            this.Property(t => t.Nombre).HasColumnName("Nombre");
            this.Property(t => t.Cantidad).HasColumnName("Cantidad");
            this.Property(t => t.IdMarca).HasColumnName("IdMarca");
            this.Property(t => t.IdCategoria).HasColumnName("IdCategoria");
            this.Property(t => t.Serie).HasColumnName("Serie");
            this.Property(t => t.Caracteristicas).HasColumnName("Caracteristicas");
            

            // Relationships
            this.HasRequired(t => t.CATEGORIA)
                .WithMany(t => t.BIENs)
                .HasForeignKey(d => d.IdCategoria)
                .WillCascadeOnDelete(false);

            this.HasRequired(t => t.MARCA)
                .WithMany(t => t.BIENs)
                .HasForeignKey(d => d.IdMarca)
                .WillCascadeOnDelete(false);

        }
    }
}
